import { DD_SYSTEM } from '@/constants/api-pre';
import { request } from '@/service/request';

export type SmsChannel = Api.Common.CommonRecord<{
  signature: string;

  code: string;

  remark: string;

  apiKey: string;

  apiSecret: string;

  callbackUrl: string;

  createTime: string;
}>;

export type SmsChannelEditAndCreateParams = CommonType.RecordNullable<
  Pick<SmsChannel, 'signature' | 'code' | 'remark' | 'status' | 'apiKey' | 'apiSecret' | 'callbackUrl'>
>;

export type SmsChannelList = Api.Common.PaginatingQueryRecord<SmsChannel>;

export type SmsChannelSearchParams = CommonType.RecordNullable<
  Pick<SmsChannel, 'signature' | 'status' | 'createTime'> & Api.Common.CommonSearchParams
>;

export function getFetchSmsChannelUrl(id: number) {
  return `${DD_SYSTEM}/sms-channel/${id}/form`;
}

export function fetchSmsChannelList(params?: SmsChannelSearchParams) {
  return request<SmsChannelList>({
    url: `${DD_SYSTEM}/sms-channel/page`,
    method: 'get',
    params
  });
}
export function fetchSmsChannelOptions() {
  return request<CommonType.OptionExtra<number>[]>({
    url: `${DD_SYSTEM}/sms-channel/options`,
    method: 'get'
  });
}
export function createSmsChannel(data: any) {
  return request<Boolean>({
    url: `${DD_SYSTEM}/sms-channel`,
    method: 'post',
    data
  });
}
export function updateSmsChannel(id: number, data?: any) {
  return request<Boolean>({
    url: `${DD_SYSTEM}/sms-channel/${id}`,
    method: 'put',
    data
  });
}
export function deleteSmsChannel(id: string) {
  return request<Boolean>({
    url: `${DD_SYSTEM}/sms-channel/${id}`,
    method: 'delete'
  });
}
